import { AmbientLight, SpotLight, DirectionalLight } from 'three'
import { gui } from '../system/gui'
import Style from '../system/style'

/**
 * 添加光源，含环境光、平行光等
 * @param {Scene} scene 
 */
function createLight(scene) {
    // 点光源
    const pointLight = new SpotLight(0xffffff, 300.0, 0, 0.3, 1)
    pointLight.position.set(0, 15, 0)
    pointLight.castShadow = true
    pointLight.shadow.autoUpdate = false
    pointLight.shadow.bias = -0.0001
    scene.add(pointLight)
    // 环境光
    const ambientLight = new AmbientLight(0xffffff, 0.5)
    ambientLight.intensity = Style.default.ambientLightIntensity
    ambientLight.name = 'ambientLight'
    scene.add(ambientLight)
}

function createLightOilModel(scene) {
    // 平行光 光照强度设置为3.0
    const directionalLight = new DirectionalLight(0xffffff, 3);
    // 设置光源的方向：通过光源position属性和目标指向对象的position属性计算
    directionalLight.position.set(80, 100, 50);
    // 对比不同入射角，mesh表面对光照的反射效果
    //directionalLight.position.set(100, 0, 0);
    //directionalLight.position.set(0, 100, 0);
    //directionalLight.position.set(100, 100, 100);
    //directionalLight.position.set(100, 60, 50)
    // 方向光默认指向xyz坐标原点
    scene.add(directionalLight);

    //const ambLight = new AmbientLight( 0xffffff, 0.2 );
    const ambLight = new AmbientLight( 0xffffff, 0.2 );
    ambLight.intensity = Style.default.ambientLightIntensity
    ambLight.name = 'ambientLight1'
    ambLight.position.set( 0, 1000, 0 );
    scene.add( ambLight );

    const dirLight1 = new DirectionalLight( 0xffffff, 2 );
    //dirLight.position.set( 1, 2, 3 );
    dirLight1.position.set( 1000, -1000, 1000 );
    scene.add( dirLight1 );

    const dirLight2 = new DirectionalLight( 0xffffff, 2 );
    //dirLight.position.set( 1, 2, 3 );
    dirLight2.position.set( -1000, -1000, 1000 );
    scene.add( dirLight2 );

    const dirLight4 = new DirectionalLight( 0xffffff, 2 );
    //dirLight.position.set( 1, 2, 3 );
    dirLight4.position.set( -1000, -1000, -1000 );
    scene.add( dirLight4 );
}

export { createLight, createLightOilModel };